//
//  CRKit.m
//  TestPrj
//
//  Created by 朱铅峰 on 2020/8/3.
//  Copyright © 2020 Xing. All rights reserved.
//

#import "CRKit.h"
#import "CRSessionCellLayoutProtocol.h"

@interface CRKit()

@property (nonatomic,strong)    id<CRCellLayoutConfig> layoutConfig;

@end

@implementation CRKit

- (instancetype)init {
    
    if (self = [super init]) {
        
    }
    return self;
}

+ (instancetype)sharedKit {
    
    static CRKit *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[CRKit alloc] init];
    });
    return instance;
}

- (void)registerLayoutConfig:(id<CRCellLayoutConfig>)layoutConfig
{
    if ([layoutConfig conformsToProtocol:@protocol(CRCellLayoutConfig)])
    {
        self.layoutConfig = layoutConfig;
    }
    else
    {
        NSAssert(0, @"class should conform to protocol of NIMLayoutConfig");
    }
}

#pragma mark - getter and setter

- (NSBundle *)resourceBundle {
    
    if (!_resourceBundle) {
        //静态库、动态库是有区分的，通过获取类所在的bundle才能精准定位
        NSBundle *bundle = [NSBundle bundleForClass:[CRKit class]];
        NSString *resourceBundlePath = [bundle pathForResource:@"CRResource" ofType:@"bundle"];
        _resourceBundle = [NSBundle bundleWithPath:resourceBundlePath];
    }
    return _resourceBundle;
}

- (NSBundle *)emoticonBundle {
    
    if (!_emoticonBundle) {
        NSBundle *bundle = [NSBundle bundleForClass:[CRKit class]];
        NSString *emoticonBundlePath = [bundle pathForResource:@"CREmoticon" ofType:@"bundle"];
        _emoticonBundle = [NSBundle bundleWithPath:emoticonBundlePath];
    }
    return _emoticonBundle;
}

- (CRKitConfig *)config {
    
    if (!_config) {
        _config = [[CRKitConfig alloc] init];
    }
    return _config;
}

- (CRKitInfo *)infoByUser:(NSString *)userId option:(CRKitInfoFetchOption *)option {

    CRKitInfo *info = nil;
    if (self.provider && [self.provider respondsToSelector:@selector(infoByUser:option:)]) {
        info = [self.provider infoByUser:userId option:option];
    }
    return info;
}

- (CRKitInfo *)infoByTeam:(NSString *)teamId option:(CRKitInfoFetchOption *)option {

    CRKitInfo *info = nil;
    if (self.provider && [self.provider respondsToSelector:@selector(infoByTeam:option:)]) {
        info = [self.provider infoByTeam:teamId option:option];
    }
    return info;

}

- (CRKitInfo *)infoBySuperTeam:(NSString *)teamId option:(CRKitInfoFetchOption *)option {

    CRKitInfo *info = nil;
    if (self.provider && [self.provider respondsToSelector:@selector(infoBySuperTeam:option:)]) {
        info = [self.provider infoBySuperTeam:teamId option:option];
    }
    return info;

}

@end
